<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Works extends CI_Controller {

	public function __construct()
    {
        parent::__construct();
        $this->load->model('User_model');
        $this->load->model('Usernum_model');
        $this->load->model('Fans_model');
        $this->load->model('Album_model');
        $this->load->model('cert_model');
    }
	

	public function index($userid)
	{
		//浏览
		$sysVisittype = _get_config('visittype');
		$this->load->service('user_service');
		$this->user_service->visit($userid, $this->loginID, $sysVisittype['home']);
		$order = $this->input->get('order');
		if (!isset($order))
		{
			$order = 1;
		}
		//-浏览
		//$this->load->service('user_service');
		$oUser = $this->user_service->get_user_homeinfo($userid, $this->loginID);

        $insid = $oUser['insid'];

        //如果此人是属于经纪公司的，此经纪公司是认证过的，则旗下所有的人都是认证过的
        if(!empty($insid)) {
            $userCert = $this->cert_model->get_by_id($insid);
            $ins_user = $this->User_model->get_info_by_id($insid);
        } else {
            //认证
            $userCert = $this->cert_model->get_by_id($userid);
        }
        //排序条件
        $order_where = 'addtime desc';
        if ($order == 2)
        {
        	$order_where = 'addtime asc';
        }
        
		// $o = $this->User_model->get_info_by_id($userid);
		$list = $this->Album_model->get_list(array('userid'=>$userid,'status'=>1),'*',$order_where);

		$photo_list = array();
		if ($list)
		{
			$photo_type = array();
			foreach ($list as $key=>$val)
			{
				if ($val['title'] != '精选作品')
				{
					if (!in_array($val['type'], $photo_type))
					{
						array_push($photo_type, $val['type']);
						$photo_list[$val['type']] = array();
					}
					array_push($photo_list[$val['type']], $val);
				}
				else 
				{
					$photo_list[0] = array();
					array_unshift($photo_list[0], $val);
				}
			}
			ksort($photo_list);
		}
		
		//相册分类
        $photo_type = _get_config('photo_type');
        $photoArr = $photo_type[6];
        if (in_array($oUser['usertype'], array(1,2)))
        {
        	$photoArr = $photo_type[$oUser['usertype']];
        }
        
        //用户类型、分类
        $userRole = '';
        if ($oUser['usertype'] == 1)
        {
        	$userRole = $oUser['role']?$oUser['role']:'模特';
        }
        elseif ($oUser['usertype'] == 2)
        {
        	$oSysType = _get_config('type');
        	$oSysType = $oSysType[2];
        	$oSysStr = '';
        	foreach ($oSysType as $key => $v)
        	{
        		if(strpos(','.$oUser['type'].',',','.$key.',')>-1)
        		{
        			if ($oSysStr)
        			{
        				$oSysStr .= ','.$v;
        			}
        			else
        			{
        				$oSysStr = $v;
        			}
        		}
        	}
        	$userRole = $oSysStr?$oSysStr:'机构';
        }
        elseif ($oUser['usertype'] == 3)
        {
        	$userRole = '公司';
        }
        elseif ($oUser['usertype'] == 4)
        {
        	$userRole = $oUser['role']?$oUser['role']:'摄影师';
        }
        elseif ($oUser['usertype'] == 5)
        {
        	$userRole = $oUser['role']?$oUser['role']:'化妆师';
        }
        elseif ($oUser['usertype'] == 6)
        {
        	if ($oUser['role'])
        	{
        		$userRole = $oUser['role'];
        	}
        	else
        	{
        		if ($oUser['type'])
        		{
        			$oSysType = _get_config('type');
        			$oSysType = $oSysType[6];
        			$userRole = $oSysType[$oUser['type']];
        		}
        		else
        		{
        			$userRole = '艺人';
        		}
        	}
        }
		
		$result = array(
			'oUser' => $oUser,
			'list' => $photo_list,
            'oCert' => $userCert,
			'photoArr' => $photoArr,
			'order' => $order,
			'userRole' => $userRole
			);
		
		if (isset($ins_user))
		{
			$result['ins_user'] = $ins_user;
		}
		$this->load->view('i/works',$result);
	}
	

}